/*
 * @description:
 * @Author: jhw
 * @Date: 2023-05-13 22:02:59
 * @LastEditors: jhw
 * @LastEditTime: 2023-05-13 22:04:52
 */
import { isExternal } from '@/utils/validate';

// TODO: row 类型定义
export const getPath = (row: any) => row.redirect || row.path;

export const getMenuList = (list: any, basePath?: string) => {
  if (!list) return [];
  // 排序
  list.sort((a: any, b: any) => (a.meta?.orderNo || 0) - (b.meta?.orderNo || 0));
  // 递归循环list，返回meta.hidden !== true的项
  return list
    .map((item: any) => {
      let path = basePath ? `${basePath}/${item.path}` : item.path;
      // 如果是外链, 则直接返回
      if (isExternal(item.path)) path = item.path;
      return {
        ...item,
        path,
        children: getMenuList(item.children, path),
      };
    })
    .filter((item: any) => item.meta?.hidden !== true);
};
